package com.googlecode.perfectable.visuable.message.server;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonTypeName;
import org.codehaus.jackson.node.ObjectNode;

import com.googlecode.perfectable.prosperable.message.ServerMessage;
import com.googlecode.perfectable.visuable.renderer.widget.WidgetVisualRenderer;
import com.googlecode.perfectable.visuable.visual.ParentVisual;
import com.googlecode.perfectable.visuable.visual.Visual;

@JsonTypeName("visual-append")
public class VisualAppendMessage implements ServerMessage {
	private static final long serialVersionUID = 1315753418571265386L;

	private final ParentVisual parent;
	private final Visual child;

	private VisualAppendMessage(ParentVisual parent, Visual child) {
		this.parent = parent;
		this.child = child;
	}

	public static VisualAppendMessage create(ParentVisual parent, Visual child) {
		return new VisualAppendMessage(parent, child);
	}

	@JsonProperty("parent-identifier")
	private final String getParent() {
		return this.parent.identifier();
	}

	@JsonProperty("child-representation")
	private final ObjectNode getChild() {
		return WidgetVisualRenderer.asNode(this.child);
	}

}
